let bgColor = '#000'
export let title = '本周销售额'
let color = [
    '#c065e7',
    '#765deb',
    '#3862d8',
    '#6a89E2',
    '#219CF9',
    '#6efbbf',
    '#40c057',
    '#ffd351',
    '#ff8e43',
    '#f56b6d'
]
let echartData = [] as any

let formatNumber = function (num: any) {
    let reg = /(?=(\B)(\d{3})+$)/g
    return num.toString().replace(reg, ',')
}
let total = echartData.reduce((a: any, b: any) => {
    return a + b.value * 1
}, 0)

export const option = {
    color: color,
    tooltip: {
        trigger: 'item'
    },
    title: [
        {
            text: '{name|' + title + '}\n{val|' + formatNumber(total) + '元}',
            top: 'center',
            left: 'center',
            textStyle: {
                rich: {
                    name: {
                        fontSize: 14,
                        fontWeight: 'normal',
                        color: '#fff',
                        padding: [10, 0]
                    },
                    val: {
                        fontSize: 32,
                        fontWeight: 'bolder',
                        color: '#fff'
                    }
                }
            }
        },
        {
            text: '单位：个',
            top: 20,
            left: 20,
            textStyle: {
                fontSize: 14,
                color: '#666666',
                fontWeight: 400
            },
            show: false
        }
    ],
    series: [
        {
            type: 'pie',
            roseType: 'radius',
            radius: ['25%', '60%'],
            center: ['50%', '50%'],
            data: echartData,
            hoverAnimation: false,
            itemStyle: {
                normal: {
                    borderColor: bgColor,
                    borderWidth: 2
                }
            },
            labelLine: {
                normal: {
                    length: 20,
                    length2: 75,
                    lineStyle: {
                        // color: '#e6e6e6'
                    }
                }
            },
            label: {
                normal: {
                    formatter: (params: any) => {
                        return (
                            '{icon|●}{name|' + params.name + '}\n{percent|' + params.percent + '%} '
                        )
                    },
                    padding: [0, -50, 0, -50],
                    rich: {
                        icon: {
                            fontSize: 16,
                            color: 'inherit'
                        },
                        name: {
                            fontSize: 18,
                            padding: [0, 0, 0, 10],
                            color: '#fff'
                        },
                        percent: {
                            fontSize: 14,
                            fontWeight: 'bolder',
                            padding: [10, -10, 0, 10],
                            color: 'inherit'
                        },
                        money: {
                            fontSize: 14,
                            padding: [8, 0, 0, 13],
                            color: 'inherit'
                        }
                    }
                }
            }
        }
    ]
}
